package cn.xrj.springcloud.controller;



import cn.xrj.springcloud.service.QcpageService;
import cn.xrj.springcloud.pojo.Qcpage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 51job招聘信息表 前端控制器
 * </p>
 *
 * @author xrj
 * @since 2019-12-13
 */
@RestController
public class QcpageProviderController {
    @Autowired
    QcpageService qcpageService;

    @Autowired
    DiscoveryClient client;

    @GetMapping("/qcpage/getAll")
    public List<Qcpage> getAll(){
        List<Qcpage> list= qcpageService.list();
        return list;
    }

    @GetMapping("/qcpage/getById/{id}")
    public Qcpage getById(@PathVariable("id")Integer id){
        Qcpage qcpage=qcpageService.getById(id);
        return qcpage;
    }

    @DeleteMapping("/qcpage/deleteById/{id}")
    public boolean deleteById(@PathVariable("id")Integer id){
        boolean flag=qcpageService.removeById(id);
        return flag;
    }

    //获取注册进来的微服务，可以获得一些微服务信息，服务发现
    @GetMapping("/qcpage/getservice")
    public Object getService(){
        List<String> service=client.getServices();
        System.out.println("service:"+service);
        List<ServiceInstance> instances=client.getInstances("springcloud-provider-jobinfo");
        for (ServiceInstance instance : instances) {
            System.out.println("serviceId:"+instance.getServiceId());
            System.out.println("InstanceId:"+instance.getInstanceId());
            System.out.println("host:"+instance.getHost());
            System.out.println("port:"+instance.getPort());
        }
        return this.client;
    }
}

